package ObserverPattern.weatherStation;

import java.util.ArrayList;

/**
 * 具体主题：气象站
 */
public class WeatherStation implements Subject {  
    private String forecastTime, forecastMess;  
    private int maxTemperature, minTemperature;  
      
    public WeatherStation() {  
    }  
  
    @Override  
    public void addObserver(Observer o) {  
        if ((o != null) && (!personList.contains(o))) {  
            personList.add(o);  
        }  
    }  
    @Override  
    public void delObserver(Observer o) {  
        if (o != null) {  
            personList.remove(o);  
        }  
    }  
    // 通知所有观察者  
    @Override  
    public void notfilyObserver() {  
        for (int i = 0; i < personList.size(); i++) {  
            Observer o = personList.get(i);  
            o.update(this);  
        }  
    }  
    /** 
     * 新消息 
     *  
     * @param t 
     * @param mess 
     * @param max 
     * @param min 
     */  
    public void doForecast(String t, String mess, int max, int min) {  
        this.forecastTime = t;  
        this.forecastMess = mess;  
        this.maxTemperature = max;  
        this.minTemperature = min;  
        System.out.println("变天了！！");
        notfilyObserver();// 如果有新的消息则调用通知观察者函数  
    }  
  
    public String getForecastTime() {  
        return forecastTime;  
    }  
  
    public String getForecastMess() {  
        return forecastMess;  
    }  
  
    public int getMaxTemperature() {  
        return maxTemperature;  
    }  
  
    public int getMinTemperature() {  
        return minTemperature;  
    }  
}